﻿using BCCServer.DAO.Interfaces;
using BCCServer.IService.IChatService;
using BCCServer.IService.ILoginService;
using BCCServer.Model.Models;
using BCCServer.Model.ModelsOut;
using BCCServer.Web.Filter;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Principal;

namespace BCCServer.Web.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ChatController : ControllerBase
    {
        private readonly IChat iChat;

        public ChatController(IChat iChat)
        {
            this.iChat = iChat;
        }

        [HttpGet]
        [Route("selChatinfo")]    
        [ManagerAuthorize]
        public BaseOut selChatinfo(string sendAccount, string receiveAccount)
        {
            try
            {
                //BCCServer.Service.LoginService.Login login=new BCCServer.Service.LoginService.Login(this.iloginDB);
                var rs = iChat.selChatinfo(sendAccount, receiveAccount);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }

        [HttpPost]
        [Route("addChatinfo")]
        [ManagerAuthorize]
        public BaseOut addChatinfo(UChatinfo uChatinfo)
        {
            try
            {
                //BCCServer.Service.LoginService.Login login=new BCCServer.Service.LoginService.Login(this.iloginDB);
                var rs = iChat.addChatinfo(uChatinfo);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }


        [HttpGet]
        [Route("selFriendsinfo")]
        [ManagerAuthorize]
        /// <summary>
        /// 根据账号查询好友
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public BaseOut selFriendsinfo(string account)
        {
            try
            {
                var rs = iChat.selFriendsinfo(account);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }


        [HttpGet]
        [Route("selChatAllUnreadinfo")]
        [ManagerAuthorize]
        /// <summary>
        /// 根据账号查询未读消息
        /// </summary>
        /// <param name="sendAccount"></param>
        /// <returns></returns>
        public BaseOut selChatAllUnreadinfo(string receiveAccount)
        {
            try
            {
                var rs = iChat.selChatAllUnreadinfo(receiveAccount);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }
    }
}
